<?php Yii::app()->clientScript->beginScript('custom-script'); ?>
<script type="text/javascript">
    function generateBarcode(code){
        var value = code;
        var btype = 'code128';
        var renderer = 'css';

        var settings = {
            output:renderer,
            bgColor: '#FFFFFF',
            color: '#000000',
            barWidth: 1,
            barHeight: 50
        };
        $("#img-barcode").html("").show().barcode(value, btype, settings);
    }
    $(document).ready(function() {
        generateBarcode('<?php echo $model->id_by_matter; ?>');
    });
</script>
<?php Yii::app()->clientScript->endScript();?>
<?php
$flashMessages = Yii::app()->user->getFlashes();
if ($flashMessages) {
    foreach($flashMessages as $key => $message) {
        echo '<div class="alert alert-' . $key . ' fade in"><button type="button" class="close" data-dismiss="alert">×</button>' . $message . "</div>\n";
    }
}
?>
<section class="add-record">
    <?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
        'id'=>'horizontalForm',
        'type'=>'horizontal',
    ));?>

    <fieldset>
        <legend>
            <?php echo Yii::t('app', 'Edit record') ?>
            <a class="btn-back pull-right" href="<?php echo $this->createUrl('task/index')?>">← <?php echo Yii::t('app', 'Back to List') ?></a>
        </legend>
        <div class="pull-right">
            <?php //echo CHtml::image(Yii::app()->getBaseUrl().'/images/Internal_ID.PNG') ?>&nbsp;&nbsp;&nbsp;&nbsp;
            <?php //echo CHtml::image(Yii::app()->getBaseUrl().'/images/print.png', '', array('onclick'=>'js:window.print()', 'style'=>'cursor: pointer;')) ?>
            <div id="img-barcode"></div>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <?php $image = CHtml::image(Yii::app()->getBaseUrl().'/images/print.png', ''); ?>
            <?php echo CHtml::link($image, $this->createUrl('task/print', array('c'=>$model->id_by_matter)), array('id'=>'print-url', 'target'=> '_blank')) ?>
        </div>
        <?php echo $form->dropDownListRow(
            $model,
            'id_client',
            $listClient,
            array(
                'disabled'=>'disabled',
            )

        )?>
        <div class="inline">
            <?php echo $form->dropDownListRow($model, 'id_contact', $listContact)?>
            <?php echo $form->checkBoxRow($model, 'mail_sent_contact', array())?>
        </div>
        <?php
        /*
        echo $form->dropDownListRow(
            $model,
            'id_transporter',
            $listComTran,
            array(
                'disabled'=>'disabled',
            )

        )
        */
        ?>
        <?php echo $form->dropDownListRow($model, 'id_tpdetail', $listTrensporter)?>
        <?php echo $form->dropDownListRow($model, 'id_attribute', Attribute::getListAttribute(), array(
            'ajax' => array(
                'type'=>'POST', //request type
                'dataType'=> 'json',
                'url'=>CController::createUrl('task/generatecode'), //url to call.
                'success'=>'function(data) {
                    generateBarcode(data.code);
                    $("#Task_id_by_matter").val(data.code);
                    $("#print-url").attr("href",data.print);
                    $("#print-url").attr("target","_blank");
                }'
            )
        ))?>
        <?php echo $form->textFieldRow($model, 'id_by_matter', array('readonly'=>'readonly')); ?>
        <div class="control-group ">
            <label for="Task_delivery_date" class="control-label required">
                <?php echo Yii::t('app', 'Delivery Date') ?> <span class="required">*</span>
            </label>
            <div class="controls">
                <?php
                $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                    'model' => $model,
                    'attribute' => 'delivery_date',
                    'options' => array(
                        'dateFormat' => 'yy/mm/dd',
                    ),
                    'htmlOptions' => array(
                        'maxlength' => 8,
                        'readonly' => 'readonly',
                    ),
                ));
                ?>
            </div>
        </div>
        <div class="control-group ">
            <label for="Task_delivery_date" class="control-label required">
                <?php echo Yii::t('app', 'Analyses Deadline') ?> <span class="required">*</span>
            </label>
            <div class="controls">
                <?php
                $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                    'model' => $model,
                    'attribute' => 'deadline',
                    'options' => array(
                        'dateFormat' => 'yy/mm/dd',
                    ),
                    'htmlOptions' => array(
                        'maxlength' => 8,
                        'readonly' => 'readonly',
                    ),
                ));
                ?>
            </div>
        </div>
        <?php echo $form->dropDownListRow($model, 'responsible', Common::get_members(Constant::LDAP_USER_GROUP), array('empty'=>Yii::t('app', 'Please select user.')))?>
        <?php echo $form->textFieldRow($model, 'client_reference'); ?>
        <?php echo $form->textAreaRow($model, 'conten_mail_client', array('rows' => 8, 'class' => 'span5')); ?>

    </fieldset>
    <div class="form-actions">
        <?php
        $this->widget('bootstrap.widgets.TbButton', array(
            'buttonType' => 'submit',
            'type' => 'primary',
            'label' => Yii::t('app', 'Submit'),
            'icon' => 'plus-sign white'
        ));
        ?>
    </div>
    <?php $this->endWidget();?>
</section>